<template>
  <div class="bigscreen">
    <el-container>
      <el-header class="bigscreen-header">
        <p class="title">{{ title }}</p>
        <div class="date">
          <span class="time">{{ time.time }}</span>
          <div class="week">
            <p>{{ time.week }}</p>
            <p>{{ time.date }}</p>
          </div>
        </div>
      </el-header>
      <el-main class="bigscreen-main">
        <div class="left-panel">
          <div class="left-card-1">
            <LeftCard1 v-if="data" :data="data"></LeftCard1>
          </div>
          <div class="left-card-2">
            <LeftCard2 v-if="data" :data="data"></LeftCard2>
          </div>
          <div class="left-card-3">
            <LeftCard3 v-if="data" :data="data"></LeftCard3>
          </div>
        </div>
        <div class="center-panel">
          <div class="center-top">
            <img
              :src="isDetail ? centerImg2 : centerImg1"
              alt=""
              @click="handleClickMap"
              ref="centerImg"
            />
            <el-select
              v-model="activeTime"
              class="center-select"
              @change="changeTime"
            >
              <el-option
                v-for="item in timeSelect"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </div>
          <div class="center-bottom">
            <CenterCard></CenterCard>
          </div>
        </div>
        <div class="right-panel">
          <div class="right-card-1">
            <RightCard1 v-if="data" :data="data"></RightCard1>
          </div>
          <div class="right-card-2">
            <RightCard2 v-if="data" :data="data"></RightCard2>
          </div>
          <div class="right-card-3">
            <RightCard3 v-if="data" :data="data"></RightCard3>
          </div>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script setup>
defineOptions({
  name: "Bigscreen",
  inheritAttrs: false,
});

import {
  ref,
  onMounted,
  computed,
  onBeforeUnmount,
  defineAsyncComponent,
  markRaw,
} from "vue";

// // // 引入modules目录下所有的模板名称数组
// import allComps from "@/components/bigscreen";
// const componentList = ref([]);
// allComps.map((v) => {
//   let item = {
//     FileName: "",
//     component: null,
//   };
//   item.FileName = v;
//   // 导入组件
//   item.component = markRaw(
//     defineAsyncComponent(() => import(`../../components/bigscreen/${v}.vue`))
//   );
//   // 组件列表追加组件信息
//   componentList.value.push(item);
// });
import LeftCard1 from "@/components/bigscreen/LeftCard1.vue";
import LeftCard2 from "@/components/bigscreen/LeftCard2.vue";
import LeftCard3 from "@/components/bigscreen/LeftCard3.vue";
import CenterCard from "@/components/bigscreen/CenterCard.vue";
import RightCard1 from "@/components/bigscreen/RightCard1.vue";
import RightCard2 from "@/components/bigscreen/RightCard2.vue";
import RightCard3 from "@/components/bigscreen/RightCard3.vue";

import ManageAPI from "@/api/manage";
import { getTime } from "@/utils/func";

import { useRouter, useRoute } from "vue-router";
import { useManageStore, useBigscreenStore } from "@/stores";

const router = useRouter();
const route = useRoute();

const manageStore = useManageStore();
const bigscreenStore = useBigscreenStore();

const title = computed(() => manageStore.settingInfo.sys_name);

const timeSelect = ref([
  { label: "最近一周", value: 3 },
  { label: "最近半年", value: 2 },
  { label: "本年", value: 1 },
]);
const activeTime = ref(1);
// 大屏统计四合一
const data = ref(null);

// 获取并刷新日期
const time = ref("");
const timeInterval = ref(null);
import centerImg1 from "../../assets/images/bigscreen/ditu.png";
import centerImg2 from "../../assets/images/bigscreen/river.png";
// 是否点击地图
const isDetail = ref(false);
const centerImg = ref();
const datatimeInterval = ref(null);

function handleClickMap() {
  isDetail.value = !isDetail.value;
  const element = centerImg.value;
  element.classList.add("animate");
  // 动画完成后的操作（例如：移除类）
  element.addEventListener(
    "animationend",
    () => {
      element.classList.remove("animate");
    },
    { once: true }
  );
}

// 右上角实时时间
function getDataTime() {
  time.value = getTime();
  setTimeout(getDataTime, 1000);
}
// 时间筛选
function changeTime(value) {
  getData();
  bigscreenStore.setBigscreenTime(value);
}
function getData() {
  ManageAPI.getStatistics({
    filter_way: activeTime.value,
  }).then((res) => {
    if (res.code === 200) {
      data.value = res.data;
    }
  });
}

onMounted(() => {
  datatimeInterval.value = setInterval(getData, DELAY);
  getData();
  getDataTime();
});
onBeforeUnmount(() => {
  if (timeInterval.value) {
    clearInterval(timeInterval.value);
  }
  if (datatimeInterval.value) {
    clearInterval(datatimeInterval.value);
  }
});
</script>
<style lang="scss" scoped>
.animate {
  opacity: 0; /* 初始状态图片透明度为0 */
  animation: fadeIn 2s forwards; /* 应用渐入动画 */
}
@keyframes fadeIn {
  to {
    opacity: 1; /* 动画结束状态图片透明度为1（完全不透明） */
  }
}
.bigscreen {
  background: url("../../assets/images/bigscreen/bj.png") no-repeat;
  background-size: 100% 100%;
  width: 100%;
  height: 100%;
  // position: absolute;
  // left: 0;
  // right: 0;
  // top: 0;
  // bottom: 0;
  font-size: 14px;
  color: #1c1c1c;
  .el-container {
    width: 100%;
    height: 100%;
  }
  &-header {
    height: auto;
    padding: 38px 54px 0 54px;
    display: flex;
    justify-content: space-between;
    .title {
      font-family: Alimama ShuHeiTi;
      font-weight: bold;
      font-size: 34px;
      color: #1a1a1a;
    }
    .date {
      display: flex;
      gap: 18px;
      .time {
        font-family: SimHei;
        font-weight: 400;
        font-size: 40px;
        color: #171717;
      }
      .week {
        font-family: Alibaba PuHuiTi;
        font-weight: normal;
        font-size: 16px;
        color: #595959;
      }
    }
  }
  &-main {
    padding: 30px 31px 41px 31px;
    // background: rgba($color: #000000, $alpha: 0.1);
    flex: 1;
    display: flex;
    gap: 14px;
    .left-panel,
    .right-panel {
      width: 329px;
    }
    .left-panel {
      display: flex;
      flex-direction: column;
      gap: 28px;
      .left-card-1 {
        height: 35%;
      }
      .left-card-2 {
        height: 12%;
      }
      .left-card-3 {
        flex: 1;
      }
    }
    .right-panel {
      display: flex;
      flex-direction: column;
      gap: 22px;
      .right-card-1 {
        height: 34%;
      }
      .right-card-2 {
        height: 26%;
      }
      .right-card-3 {
        flex: 1;
      }
    }
    .center-panel {
      position: relative;
      flex: 1;
      display: flex;
      flex-direction: column;
      .center-top {
        display: flex;
        justify-content: center;
        align-content: center;
        flex: 1;
        .center-select {
          width: 100px;
          position: absolute;
          right: 0;
          top: 0;
        }
      }
      .center-bottom {
        height: 270px;
      }
    }
  }
}
</style>
